package com.blockmeta.bbs.businesslibrary.adapter;

import android.content.Context;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.blockmeta.bbs.baselibrary.base.adapter.BaseAdapter;
import com.blockmeta.bbs.businesslibrary.R;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseViewHolder;

import java.io.File;
import java.util.List;

/**
 * Created by AirThor
 * Date 2018/1/23.
 * 发帖时的图片展示
 */

public class ThumbAdapter extends BaseAdapter<String,BaseViewHolder> {
    private Context mContext;
    private List<String> pics;
    private RecyclerView mRecyclerView;
    public ThumbAdapter(Context context, RecyclerView recyclerView, int layoutResId, @Nullable List<String> data) {
        super(layoutResId, data);
        mContext = context;
        pics=data;
        mRecyclerView = recyclerView;
    }

    @Override
    protected void convert(BaseViewHolder helper, final String item) {
        Glide.with(mContext).load(new File(item)).into((ImageView) helper.getView(R.id.iv_thumbnail));
        helper.getView(R.id.iv_del_thumbnail).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pics.remove(item);
                notifyDataSetChanged();
                if (getItemCount()==0) mRecyclerView.setVisibility(View.GONE);
            }
        });
    }
}
